﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BuySoftwareOnline.Domain.Abstract;

namespace BuySoftwareOnline.Domain.Concrete
{
    public class VersionRepository : IVersionRepository
    {
        private BuySoftwareOnlineDataContext context;

        public VersionRepository()
        {
            context = new BuySoftwareOnlineDataContext();
        }

        public IQueryable<Version> Versions
        {
            get
            {
                return context.Versions;
            }
        }

        public void SaveVersion(Version version)
        {
            if (version.VersionID == 0)
            {
                context.Versions.InsertOnSubmit(version);
            }
            else
            {
                context.Versions.Attach(version);
                context.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, version);
            }
            context.SubmitChanges();
        }

        public void DeleteVersion(Version version)
        {
            context.Versions.DeleteOnSubmit(version);
            context.SubmitChanges();
        }
    }
}
